<?php
/**
 * RedXenon Framework
 * 
 * LICENSE
 * 
 * This source file is subject to the New BSD license that is bundled
 * with this package in the file LICENSE.txt
 * A copy of this license can be found in the world-wide-web at this URL:
 * http://www.redxenon.com/license/new-bsd-license.txt
 */

/* Abstract Class */
require_once("RXQuery.php");

/** 
 * RedXenon Database (RXDelete.php)
 * Class to manage Database Delete Queries
 * 
 * @category RedXenon
 * @package RedXenon_Database
 * @copyright Copyright (c) 2011 Red Xenon (http://www.redxenon.com)
 * @version $Id: RXDelete.php 1.0 2011-09-06 $ 
 */
class RXDelete extends RXQuery{

	private $fields;
	private $values;
	
	/**
	 * Constructor that calls the parent class
	 * @param RXDatabaseConnection $connection
	 * @param String $query
	 * @see RXQuery::__construct 
	 */
	public function __construct($connection = NULL, $query = NULL){
		$this->fields = array();
		$this->values = array();
		parent::__construct($connection, $query);
	}
	
	/**
	 * Destructor
	 */
	public function __destruct(){
		parent::__destruct();
	}

	public function buildQuery(){
		/* DELETE  */
		$this->query = "DELETE FROM ";
		
		/* TABLE */
		if(is_array($this->tables)){
			$this->query .=  $this->tables[0]["tableName"];
		}else{
			$this->query .= $this->tables;
		}
		
		/* WHERE */
		if($this->where){
			$this->query .= " WHERE ".$this->where;
		}		
	}
	
	public function execute(){
		if(!$this->query){
			$this->buildQuery();
		}
		
		if(parent::exec()){
			return TRUE;
		}else{
			return FALSE;
		}
	}
}

?>